<template>
  <div class="big">
    <div :class="{ nav: show }" v-show="show">
      <van-nav-bar>
        <template #left>
          <van-icon
            name="arrow-left"
            size="20"
            color="#656566"
            fixed="true"
            @click="back"
          />
        </template>
      </van-nav-bar>
    </div>

    <div class="text">
      <p class="title">{{ cinemaInfo.name }}</p>
    </div>

    <div class="tag">
      <div
        class="serve"
        v-for="(ser, index) in cinemaInfo.services"
        :key="index"
      >
        {{ ser.name }}
      </div>
      <div class="icon"><van-icon name="arrow" color="#ffb232" /></div>
    </div>

    <div class="address">
      <p class="ii1"><van-icon name="location-o" size="25px" /></p>
      <p class="add">{{ cinemaInfo.address }}</p>
      <p class="tel"><van-icon name="phone-o" size="25px" /></p>
    </div>

    <div class="lunbo">
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div
            class="swiper-slide"
            v-for="info in cinemaFilms"
            :key="info.filmId"
          >
            <img :src="info.poster" alt="" style="width: 70%; height: 100%" />
          </div>
        </div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
      </div>
    </div>

    <div class="xinxi">
      <p class="biaoti">
        {{ duiying.name }}<em>{{ duiying.grade }}</em
        ><span>分</span>
      </p>
      <p class="icon"><van-icon name="arrow" size="10px" /></p>
      <p class="miaoshu">
        {{ duiying.category }} | {{ duiying.runtime }}分 | {{ daoyan }} |
        <span v-for="(yan,index) in duiying.actors" :key="index">{{ yan.name }}</span>
      </p>
    </div>

    <div class="bar">
      <van-tabs v-model="active" @click="tabs">
        <van-tab
          :title="time | formatDate"
          v-for="(time, index) in duiying.showDate"
          :key="index"
        >
          <div class="pian" v-for="(pai, index) in anpai" :key="index">
            <div class="time">
              <p class="start">{{ pai.showAt | formatDate1 }}</p>
              <p class="end">{{ pai.endAt | formatDate1 }}散场</p>
            </div>
            <div class="lan">
              <p class="lang">{{ pai.filmLanguage }}</p>
              <p class="ting">{{ pai.imagery + pai.hallName}}</p>
            </div>
            <div class="spice">￥0</div>
            <div class="anniu" @click="tiao(filmId)">购票</div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Tab, Tabs } from "vant";

Vue.use(Tab);
Vue.use(Tabs);
import Swiper from "swiper";
import "swiper/swiper.min.css";
import { getDistrict, getFilmsInfo, getCineAndFilm } from "@/request/request";

export default {
  async created() {},
  computed: {},
  filters: {
    formatDate(val) {
      let date = new Date(val * 1000);
      let month = date.getMonth() + 1;
      let day = date.getDate();
      return month + "月" + day + "日";
    },
    formatDate1(val) {
      let date = new Date(val * 1000);
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let hours = date.getHours();
      let seconds = date.getSeconds();
      if(seconds < 1){seconds += '0'}
      return hours + ":" + seconds;
    },
  },
  data() {
    return {
      createFilmId: 0,
      active: 0,
      // 影院排片
      cinemaFilms: [],
      // 影院基本信息
      cinemaInfo: "",
      // 影院ID
      cinemaId: 0,
      // 导航栏是否显示
      show: true,
      filmId: 0,
      yanyuan: "",
      daoyan: "",
      anpai: [],
      duiying: {},
    };
  },
  async mounted() {
    this.cinemaId = this.$route.query.id;
    // 影院详情
    let res = await getDistrict(this.cinemaId);
    // 影院详情
    this.cinemaInfo = res.data.cinema;

    // 影片列表
    let list = await getFilmsInfo(this.cinemaId);
    this.cinemaFilms = list.data.films;
    this.filmId = this.cinemaFilms[0].filmId;

    // 根据对应ID查找对应影片信息
    this.duiying = this.cinemaFilms.find((item) => item.filmId == this.filmId);
    this.daoyan = this.duiying.actors[0].name;
 
    let msg = await getCineAndFilm(this.cinemaId, this.filmId,this.duiying.showDate[0]*1000);
    this.anpai = msg.data.schedules;
    // 滚动条监听事件
    window.addEventListener("scroll", this.scroll);

    let that = this;
    // this.$nextTick(() => {
    var swiper = new Swiper(".swiper-container", {
      slidesPerView: 2,
      centeredSlides: true,
      paginationClickable: true,
      spaceBetween: 30,
      centeredSlides: true,

      on: {
        slideChangeTransitionEnd: function () {
          that.filmId = that.cinemaFilms[this.activeIndex].filmId;

          that.duiying = that.cinemaFilms.find(
            (item) => item.filmId == that.filmId
          );

          that.daoyan = that.duiying.actors[0].name;
          getCineAndFilm(that.cinemaId, that.filmId,that.duiying.showDate[0]*1000).then((msg) => {
            that.anpai = msg.data.schedules;
          });
          
        },
      },
      // });
    });
  },
  methods: {
    tiao(id){
      this.$router.push({ path: "/movie/cinemas", query: { id } });
    },
    back() {
      this.$router.push("/movie");
    },
    scroll() {
      if (document.documentElement.scrollTop >= 100) {
        this.show = true;
      } else {
        this.show = false;
      }
    },
    tabs(name, title) {
      let time = this.duiying.showDate[this.active]*1000
      getCineAndFilm(this.cinemaId, this.filmId,time).then((msg) => {
        this.anpai = msg.data.schedules;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.pian {
  display: flex;
  justify-content: space-around;
  padding: 15px;
  background-color: #fff;
  height: 74px;
  .start {
    color: #191a1b;
    font-size: 15px;
    margin-left: 10px;
    margin-right: 60px;
  }
  .end {
    color: #797d82;
    margin: 2px 0 2px 0;
    font-size: 13px;
    margin-left: 10px;
    margin-top: 5px;
  }
}
.lan {
  color: #191a1b;
  font-size: 15px;
  margin-left: 10px;
  margin-right: 60px;
}
.ting {
  color: #797d82;
  margin: 2px 0 2px 0;
  font-size: 13px;
  
  margin-top: 5px;
}
.spice {
  color: #ff5f16;
  font-size: 15px;
  margin-left: 80px;
  margin-top: 10px;
}
.anniu {
  margin-top: 5px;
  width: 50px;
  height: 25px;
  margin-left: 10px;
  color: #ff5f16;
  text-align: center;
  border: 1px solid #ff5f16;
}
.big {
  background-color: #fff;
  overflow: hidden;
  padding-bottom: 50px;
}
.lunbo {
  height: 160px;
  padding: 15px 0px;
  overflow: hidden;
}
.xinxi {
  color: #191a1b;
  padding: 10px 5px 0px 0px;
  font-size: 15px;
  text-align: center;
  background-color: #fff;

  .biaoti em {
    color: #ffb232;
    font-style: 16px;
    text-indent: 2px;
  }
  .biaoti span {
    color: #ffb232;
  }

  .icon {
    text-align: right;
  }
  .miaoshu {
    color: #797d82;
    font-size: 13px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-indent: 50px;
  }
}
.nav {
  position: fixed;
  top: 0;
  height: 48px;
  width: 100%;
  z-index: 9999999;
}
// 影院名
.text {
  margin-top: 46px;
  .title {
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 17px;
    padding: 0 15px;
    color: #191a1b;
    background-color: #fff;
  }
}
// 影院服务
.tag {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  background-color: #fff;
  .serve {
    margin-right: 10px;
    text-align: center;
    width: 60px;
    border: 1px solid #ffb232;
    font-size: 13px;
    color: #ffb232;
    border-radius: 1px;
  }
}

// 影院地址
.address {
  display: flex;
  height: 50px;
  line-height: 50px;
  padding: 0 0 0 17px;
  justify-content: space-between;
  background-color: #fff;

  .add {
    font-size: 14px;
    color: #191a1b;
    padding: 0 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

//swiper
html,
body {
  position: relative;
  // height: 100%;
}
body {
  background: #eee;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #000;
  margin: 0;
  padding: 0;
}
.swiper-container {
  width: 100%;
  height: 100%;
}
.swiper-slide {
  overflow: hidden;
  text-align: center;
  font-size: 18px;
  // background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  transition: 300ms;
  transform: scale(0.8);
}
.swiper-slide-active,
.swiper-slide-duplicate-active {
  transform: scale(1);
}
</style>
